﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CocisWeb.src;
using CocisDAL;
using CocisModel;

namespace CocisWeb.admin
{
    public partial class Password :BasePage
    {
        public LoginDAL dal = new LoginDAL();
        public MakeMD5String md5 = new MakeMD5String();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonUpdate_Click(object sender, EventArgs e)
        {
            string pwd = this.TextBoxOld.Text;
            string paswd = md5.StringToMD5(pwd).ToString();
            string news = this.TextBoxNews.Text;
            string newspaswd = md5.StringToMD5(news);
            UserInfo userInfo = Session["userInfo"] as UserInfo;

            int check = dal.CheckPassword(userInfo.UserId, paswd);
            if (check > 0)
            {

                int temp = dal.UpdatePassword(userInfo.UserId, newspaswd);
                if (temp > 0)
                {

                    ClientScript.RegisterStartupScript(this.GetType(), "a", "<script language=javascript>alert('User password updated successfully!Please remember new password！')</script>");
                }

            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "d", "<script language=javascript>alert('Old password is not correct！')</script>");

            }


         


        }
    }
}
